using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class GUIToggle : CustomGUIController
{
    bool nowState = false;
    bool preState = false;

    public event UnityAction<bool> toggleEvent;

    protected override void DrawStyleOn()
    {
        nowState = GUI.Toggle(pos.Pos, nowState, content, style);

        if (preState != nowState)
        {
            preState = nowState;
            toggleEvent?.Invoke(nowState);
        }
    }

    protected override void DrawStyleOff()
    {
        nowState = GUI.Toggle(pos.Pos, nowState, content);

        if (preState != nowState)
        {
            preState = nowState;
            toggleEvent?.Invoke(nowState);
        }
    }

    public void ChangeState(bool state)
    {
        nowState = state;
        if (preState != nowState)
        {
            toggleEvent?.Invoke(nowState);
        }
        preState = nowState;
    }
}
